const Koa = require('koa');
const app = new Koa();
const router = require('koa-router')();
const index = require('./routes/index')

const PORT = 3001;

// app.use(async (ctx, next) => {
//   // 请求地址 请求方式 请求参数 (get post)
//   ctx.body = {
//     data: {
//       path: ctx.path,
//       url: ctx.url,
//       query: ctx.query,
//       method: ctx.method
//     }
//   }
//   await next();
//   ctx.body = '1212'
// })
// console.log(index.routes, 'index----------')
app.use(index.routes(), index.allowedMethods())

app.use(async (ctx, next) => {
  const start = new Date()
  await next()
  const ms = new Date() - start
  console.log(`${ctx.method} ${ctx.url} - ${ms}ms`)
})

app.listen(PORT, () => {
  console.log('server port is :', `http://localhost:${PORT}`)
})




